package com.tang4j.model.factory;

import com.tang4j.core.model.easyui.TreeGrid;
import com.tang4j.core.util.InstanceUtil;
import com.tang4j.model.ThSysDept;
import com.tang4j.model.response.ThSysUserDto;

import java.util.List;

public class TreeGridFactory {

    public static TreeGrid createByDept(ThSysDept dept) {
        return new TreeGrid(dept.getId(), dept.getPId(), dept.getName());
    }

    public static List<TreeGrid> createByDept(List<ThSysDept> deptList) {
        List<TreeGrid> treeGridList = InstanceUtil.newArrayList();
        deptList.forEach(dept -> treeGridList.add(TreeGridFactory.createByDept(dept)));
        return treeGridList;
    }

    /**
     * 部门下的用户转成 TreeGrid 格式
     *
     * @param userDto 用户信息
     * @return TreeGrid
     */

    public static TreeGrid createByThSysUserDtoWithUser(ThSysUserDto userDto) {
        return new TreeGrid(userDto.getId(), userDto.getDeptId(), userDto.getName());
    }
    public static TreeGrid createByThSysUserDtoWithDept(ThSysUserDto userDto) {
        return new TreeGrid(userDto.getDeptId(), userDto.getDeptPId(), userDto.getDeptName());
    }


    /**
     * 部门下的用户集合转成 TreeGrid 格式
     *
     * @param userDtoList 用户信息集合
     * @return TreeGrid
     */

    public static List<TreeGrid> createByThSysUserDto(List<ThSysUserDto> userDtoList) {
        List<TreeGrid> grids = InstanceUtil.newArrayList();
        userDtoList.forEach(userDto -> grids.add(TreeGridFactory.createByThSysUserDtoWithUser(userDto)));
        return grids;
    }
    public static List<TreeGrid> createByThSysUserDtoWithDept(List<ThSysUserDto> userDtoList) {
        List<TreeGrid> grids = InstanceUtil.newArrayList();
        userDtoList.forEach(userDto -> grids.add(TreeGridFactory.createByThSysUserDtoWithDept(userDto)));
        return grids;
    }
}
